<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>电子账户管理</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">电子账户</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show" style="margin-bottom:1%;">
                    <div class="layui-row">
                        <div class="layui-form">
                            <div class="layui-form-item">
                                <div class="layui-input-inline">
                                    <input type="text" name="drawDayEndTime" id="drawDayEndTime" autocomplete="off" placeholder="结束时间" class="layui-input">
                                </div>
                                <button id="search" class="layui-btn" data-type="reload">搜索</button>
                            </div>
                        </div>
                        <div class="layui-form-item" style="padding-top: 15px;">
                            <blockquote class="layui-elem-quote" id="amountTip">
                                概况: 当日总金额:<sapn id="totalCount" style="color: blue; margin-right: 10px;"></sapn>|
                                目前可用总金额:<span id="totalAgentProfit" style="color: green; margin-right: 10px;"></span>
                            </blockquote>
                        </div>
                    </div>
                </div>

                <table id="electricList" lay-filter="electricList"></table>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="electricBa">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
</script>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.js"></script>
<script>

    layui.use(['admin','table','util','admin','form','laydate'], function(){
        var table = layui.table
        ,$ = layui.$
        ,form = layui.form
        ,admin = layui.admin
         ,laydate = layui.laydate
        ,element = layui.element;

        element.render('breadcrumb', 'breadcrumb');//渲染导航信息
        table.render({
            elem: '#electricList'
            ,url: layui.setter.baseUrl + '/electric/list'
            ,where: {
                access_token: layui.data(layui.setter.tableName).access_token
            }
            ,id: 'tableReload'
            ,cols: [[
                // {field:'mchId', title: '序号'}
                // ,{field: 'mchId',title: '商户ID'}
                // ,{field: 'name',title: '商户名称'}
                // ,{field:'agentAccount.balance', width: 200, title: '当日账户余额', templet: '<div style="width: 200px">{{ d.balance }}</div>' }
                // ,{field:'agentAccount.todayIncome',width: 270,  title: '目前账户余额', templet: '<div style="width: 300px">{{ d.todayIncome }}</div>' }
                // ,{field:'agentAccount.updateTime', width: 400, title: '变更时间', templet: '<div style="width: 400px">{{ layui.util.toDateString(d.updateTime) }}</div>' }
                // ,{field:'edit', title: '操作',toolbar: '#electricBa'}
                {field:'mchId', title: '序号', align: 'center'}
                ,{field: 'mchId',title: '商户ID', align: 'center'}
                ,{field: 'name',title: '商户名称', align: 'center'}
                ,{field:'balance', title: '当日账户余额', templet: '<div style="width: 20%; text-align: center;">{{ d.balance }}</div>', align: 'center' }
                ,{field:'todayIncome', title: '目前账户余额', templet: '<div style="width: 20%; text-align: center;">{{ d.todayIncome }}</div>', align: 'center' }
                ,{field:'updateTime', title: '变更时间', templet: '<div style="width: 20%; text-align: center;">{{ layui.util.toDateString(d.updateTime) }}</div>', align: 'center' }
                ,{field:'edit', title: '操作',toolbar: '#electricBa'}
            ]]
            ,page: true
            ,skin: 'line'
        });
        //监听工具条
      /*  table.on('tool(electricList)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            if(layEvent === 'edit'){ //编辑
                location.hash="/electric/update/id=" + data.id + "/accountNo=" + data.accountNo;
            } else if(obj.event === 'del'){
                layer.confirm('确认删除么', function(index){
                    admin.req({
                        type: 'get',
                        url: layui.setter.baseUrl + '/electric/delete',
                        data: {
                            id: data.id,
                        },
                        success: function(res){
                            if(res.code == 0) {
                                layer.msg('删除成功', {
                                    icon: 1
                                });
                                table.reload("tableReload");
                            }
                        }
                    });
                });
            }
        });*/


        //监听工具条
        table.on('tool(electricList)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                location.href = layui.setter.baseLocal + "merchant/electric/detail/mchId=" + data.mchId;
            }
        });


        // 搜索
        var $ = layui.$, active = {
            reload: function(){
                var accountNo = $('#accountNo').val();

                var drawDayEndTime = $("#drawDayEndTime").val();
                //执行重载
                table.reload('tableReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        drawDayEndTime:drawDayEndTime
                    }
                });
            }
        };

        $('#search').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        laydate.render({
            elem: '#drawDayEndTime'
            ,type: 'datetime'
            ,format: 'yyyy-MM-dd HH:mm:ss'
        });
        // 渲染表单
        form.render();

    })


</script>